Imports AjaxControlToolkit

Partial Class WebForm_CommonControl_SimpleListControl
    Inherits System.Web.UI.UserControl
    Implements IListControl, ITextControlExtension

    Protected Sub Page_DataBiding(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    End Sub

    Protected Sub rp_ItemCommand(ByVal sender As Object, ByVal e As RepeaterCommandEventArgs)
        Select Case e.CommandName
            Case "Do"
                PopupControlExtender.GetProxyForCurrentPopup(Page).Commit(TryCast(e.CommandSource, LinkButton).Text)
        End Select
    End Sub

    Public Property DataTextField() As String Implements IListControl.DataTextField
        Get
            Return ViewState("DataTextField")
        End Get
        Set(ByVal value As String)
            ViewState("DataTextField") = value
        End Set
    End Property

    Public Property DataValueField() As String Implements IListControl.DataValueField
        Get
            Return ViewState("DataValueField")
        End Get
        Set(ByVal value As String)
            ViewState("DataValueField") = value
        End Set
    End Property

    Public Property DataSource() As Object Implements IListControl.DataSource
        Get
            Return rp.DataSource
        End Get
        Set(ByVal value As Object)
            rp.DataSource = value
        End Set
    End Property

    Public Property Text() As String Implements ITextControl.Text
        Get
            '
        End Get
        Set(ByVal value As String)
            '
        End Set
    End Property

    Public Property SelectedText() As String Implements ITextControlExtension.SelectedText
        Get
            Return String.Empty
        End Get
        Set(ByVal value As String)

        End Set
    End Property

    Public Function FindValue(ByVal text As String) As String Implements ITextControlExtension.FindValue
        For Each item As RepeaterItem In rp.Items
            If (TryCast(item.FindControl("lkn"), LinkButton).Text = text) Then
                Return TryCast(item.FindControl("lkn"), LinkButton).CommandArgument
            End If
        Next

        Return String.Empty
    End Function

    Public Function FindText(ByVal value As String) As String Implements ITextControlExtension.FindText
        For Each item As RepeaterItem In rp.Items
            If (TryCast(item.FindControl("lkn"), LinkButton).CommandArgument = text) Then
                Return TryCast(item.FindControl("lkn"), LinkButton).Text
            End If
        Next

        Return String.Empty
    End Function
End Class
